package yuejian_07.yuejian_07.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.List;

import yuejian_07.yuejian_07.R;
import yuejian_07.yuejian_07.RetrofitListener;
import yuejian_07.yuejian_07.adapter.TrainListAdapter;
import yuejian_07.yuejian_07.javabean.Train;
import yuejian_07.yuejian_07.model.TrainModel;

/**
 * Created by dell on 2017/10/23.
 */

public class TrainCaijiActivity extends Activity implements RetrofitListener<List<Train>> {
    private RecyclerView recyclerView;
    private ImageView img_return;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_train_caiji);
        initViews();
        initEvents();
        getCaijilist();
    }

//    private void initEvents(){
//        img_return.setOnClickListener(new View.OnClickListener() {//返回
//            @Override
//            public void onClick(View v) {
//                finish();
//            }
//        });
//    }

    private void initViews(){

        recyclerView= (RecyclerView)findViewById(R.id.rv_list1);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        img_return=(ImageView) findViewById(R.id.img_return);
        recyclerView.setItemAnimator(new DefaultItemAnimator());

    }
    private void initEvents(){
        img_return.setOnClickListener(new View.OnClickListener() {//返回
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    void getCaijilist(){
        TrainModel trainModel=new TrainModel();
        trainModel.caijilist(this);
    }

    @Override
    public void onSuccess(List<Train> data ){

        System.out.printf("data");
        recyclerView.setAdapter(new TrainListAdapter(TrainCaijiActivity.this,data));
    }

    @Override
    public void onFail(){ Toast.makeText(this, "网络发生错误", Toast.LENGTH_SHORT).show();}
}
